package com.books.dao;

import com.books.model.entity.question.Answer;
import com.books.model.entity.question.Question;
import com.books.model.entity.question.ReplyAnswer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author 饿熊的咆哮
 * @Date 2021/10/30 8:24
 * @Version 1.0
 */
@Component
public class ReplyAnswerDao {
    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 创建对象
     */
    public void addReplyAnswer(ReplyAnswer replyAnswer) {
        mongoTemplate.save(replyAnswer);
    }

    public ReplyAnswer findReplyAnswerById(String _id){
        Query query = new Query(Criteria.where("_id").is(_id));
        ReplyAnswer replyAnswer = mongoTemplate.findOne(query, ReplyAnswer.class);
        System.out.println(replyAnswer);
        return replyAnswer;
    }

    public List<ReplyAnswer> findReplyAnswerByAnswerId(String answerId){
        Query query = new Query(Criteria.where("answerId").is(answerId));
        List<ReplyAnswer> replyAnswers = mongoTemplate.find(query, ReplyAnswer.class);
        System.out.println(replyAnswers);
        return replyAnswers;
    }

}
